import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import MicroAppContainer from '../views/MicroAppContainer.vue'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '首页'
    }
  },
  {
    path: '/user',
    name: 'User',
    component: MicroAppContainer,
    meta: {
      title: '用户管理'
    }
  },
  {
    path: '/order',
    name: 'Order',
    component: MicroAppContainer,
    meta: {
      title: '订单管理'
    }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫：更新页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
